home *** CD-ROM | disk | FTP | other *** search
- /* Functions related to time.
-
- Revision History:
-
- 91/11/14 AIH
- - Fixed up the delay function so it chooses between allowing background
- tasks for long delays or calling the Delay trap for short delays.
-
- 91/06/13 AIH
- - Added function to delay for a specified number of ticks
-
- 91/03/23 AIH
- - Merged TicksLib into TimeLib
- - Changed TicksType and TimeType to size_t
- - Removed #define which made TickCount be the global variable Ticks,
- for compatability with AUX
- - Changed TimeStartupSame in to a more general function
-
- 91/01/31 Ari Halberstadt (AIH)
- - Created this file by moving a couple of functions out of MacLib.c */
-
- #include "TimeLib.h"
-
- /* return time (in seconds) at which the computer was started up */
- TimeType TimeStartup(void)
- {
- TimeType secs; /* current time */
-
- GetDateTime(&secs);
- return(secs - (TickCount() / TICKS_SEC));
- }
-
- /* true if t2 is within ±thresh seconds of t1 */
- Boolean TimeSame(TimeType t1, TimeType t2, TimeType thresh)
- {
- return(t1 - thresh <= t2 && t2 <= t1 + thresh);
- }
-
- /* Suspend execution for the specified number of ticks. To the calling
- process this is identical to using Delay, but it allows other
- processes to receive time. Using WNE is too slow, resulting in delays
- in excess of small requested periods, so EventAvail is used instead.
- Even using EventAvail, short delays could take longer than expected,
- so we use the "Delay" function for very short delays. The actual delay
- could be larger than the requested delay due to unpredictable system
- usage. If you need accurate timing, use the Time Manager. */
- void TimeDelay(TicksType delay)
- {
- const TicksType small = TICKS_SEC / 2;
- EventRecord event;/* dummy event record */
- TicksType start; /* time when we started */
- TicksType stop; /* time when we stoped */
-
- start = TickCount();
- if (delay < small)
- Delay(delay, (long *) &stop);
- else {
- while (TickCount() - start < delay)
- (void) EventAvail(0, &event);
- stop = TickCount();
- }
- ensure(stop - start >= delay);
- }
-
-